# -*- coding:UTF-8 -*-
# 迭代器
'''
Created on 2013-6-5

@author: hanjiewu
'''
# 生成器表达式，可以避免一次性将数据都生成到列表中，可以在需要的时候在触发
myTuple = (123, 'xyz', 45.67)
i = iter(myTuple)
print i.next()
print i.next()
print i.next()
try:
    print i.next()
except StopIteration, e:
    print 'None'
myDict = {'a': 1, 'b':2, 'c':3, 'd': 4}
try:
    for eachkey in myDict:
        print eachkey, myDict[eachkey]
        del myDict[eachkey]
except RuntimeError:
    print 'Error'

rows = [1, 2, 3, 17]
def clos():
    yield 56
    yield 2
    yield 1
#生成器表达式
x_product_pairs = ((i, j) for i in rows for j in clos())
for pair in x_product_pairs:
    print pair,
print 
#计算文件最大行的单词数
print max(len(x.strip()) for x in open(r'F:\workspace\mypython\makeTextFile.py'))
